package com.hunt.controller;

import com.hunt.model.dto.PageInfo;
import com.hunt.service.ComPlaintFeedBackService;
import com.hunt.service.SystemService;
import com.hunt.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;

@Api("手机端意见反馈")
@Controller
@RequestMapping("/app/feedback")
public class ComPlaintFeedBackController extends BaseController{
    @Autowired
    private ComPlaintFeedBackService ComPlaintFeedBackService;
    @ApiOperation(value = "意见反馈加入", httpMethod = "POST", produces = "application/json", response = Result.class)
    @ResponseBody
    @RequestMapping(value = "insert", method = RequestMethod.POST)
    public Result insert(@RequestParam(value = "content") String content,
                         @RequestParam(value = "linkmethod",required = false) String linkmethod,@RequestParam(value = "title") String title,
                         @RequestParam(value = "userid",required = false) String userid){
        Date da=new Date();
        SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");
        String ctime = formatter.format(da);
        int returnresult= ComPlaintFeedBackService.insert(content,linkmethod,ctime,title,userid);
       if(returnresult>0){
           return Result.success();
       }
       else {
           return  Result.error();
       }
    }
    @ApiOperation(value = "跳转至意见反馈统计模块", httpMethod = "GET", produces = "text/html")//
    @RequestMapping(value = "feedbackCount", method = RequestMethod.GET)
    public String feedbackCount() {
        return "system/feedbackCount";
    }

    @ApiOperation(value = "获取意见反馈统计", httpMethod = "GET",produces = "application/json", response = PageInfo.class)
    @ResponseBody
    @RequestMapping(value = "feedbackget", method = RequestMethod.GET)
    public PageInfo feedbackget(@RequestParam(value = "page",defaultValue = "1") Integer page ,@RequestParam(value = "rows",defaultValue = "3") Integer rows) {
       return  ComPlaintFeedBackService.getfeedback(page,rows);
    }
}
